<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>usr_23 - Vim Documentation</title>
<meta name="Generator" content="Vim/8.0">
<meta name="plugin-version" content="vim8.0">
<meta name="syntax" content="help">
<meta name="settings" content="no_pre,use_css,expand_tabs">
<link rel="stylesheet" href="style.css" type="text/css" />

<script src="jquery.min.js" type="text/javascript"></script>
<script src="mark-current-page.js" type="text/javascript"></script>
</head>

<body>

<header>

<div class="header">
  <a href="http://vim-jp.org/">vim-jp</a>
  / <a href="http://vim-jp.org/vimdoc-en/">vimdoc-en</a>
  / usr_23<br />
  <a name="top"></a><h1>usr_23 - Vim Documentation</h1>
  <a href="index.html">Return to main</a>

  <span class="EnglishJapaneseLink">
    <span class="CurrentLanguage">English</span>
  </span>
</div>
</header>

<nav>
<dl>

<dt>BASIC</dt>
<dd><ul>
<li><a href="quickref.html">quickref</a></li>
<li><a href="sponsor.html">sponsor</a></li>
</ul></dd>

<dt>USER MANUAL</dt>
<dd><ul>
<li><a href="usr_toc.html">usr_toc</a></li>
</ul></dd>

<dt>Getting Started</dt>
<dd><ul>
<li><a href="usr_01.html">usr_01</a></li>
<li><a href="usr_02.html">usr_02</a></li>
<li><a href="usr_03.html">usr_03</a></li>
<li><a href="usr_04.html">usr_04</a></li>
<li><a href="usr_05.html">usr_05</a></li>
<li><a href="usr_06.html">usr_06</a></li>
<li><a href="usr_07.html">usr_07</a></li>
<li><a href="usr_08.html">usr_08</a></li>
<li><a href="usr_09.html">usr_09</a></li>
<li><a href="usr_10.html">usr_10</a></li>
<li><a href="usr_11.html">usr_11</a></li>
<li><a href="usr_12.html">usr_12</a></li>
</ul></dd>

<dt>Editing Effectively</dt>
<dd><ul>
<li><a href="usr_20.html">usr_20</a></li>
<li><a href="usr_21.html">usr_21</a></li>
<li><a href="usr_22.html">usr_22</a></li>
<li><a href="usr_23.html">usr_23</a></li>
<li><a href="usr_24.html">usr_24</a></li>
<li><a href="usr_25.html">usr_25</a></li>
<li><a href="usr_26.html">usr_26</a></li>
<li><a href="usr_27.html">usr_27</a></li>
<li><a href="usr_28.html">usr_28</a></li>
<li><a href="usr_29.html">usr_29</a></li>
<li><a href="usr_30.html">usr_30</a></li>
<li><a href="usr_31.html">usr_31</a></li>
<li><a href="usr_32.html">usr_32</a></li>
</ul></dd>

<dt>Tuning Vim</dt>
<dd><ul>
<li><a href="usr_40.html">usr_40</a></li>
<li><a href="usr_41.html">usr_41</a></li>
<li><a href="usr_42.html">usr_42</a></li>
<li><a href="usr_43.html">usr_43</a></li>
<li><a href="usr_44.html">usr_44</a></li>
<li><a href="usr_45.html">usr_45</a></li>
</ul></dd>

<dt>Making Vim Run</dt>
<dd><ul>
<li><a href="usr_90.html">usr_90</a></li>
</ul></dd>

<dt>General subjects</dt>
<dd><ul>
<li><a href="intro.html">intro</a></li>
<li><a href="index.html">help</a></li>
<li><a href="helphelp.html">helphelp</a></li>
<li><a href="vimindex.html">index</a></li>
<li><a href="tags.html">tags</a></li>
<li><a href="howto.html">howto</a></li>
<li><a href="tips.html">tips</a></li>
<li><a href="message.html">message</a></li>
<li><a href="quotes.html">quotes</a></li>
<li><a href="todo.html">todo</a></li>
<li><a href="debug.html">debug</a></li>
<li><a href="develop.html">develop</a></li>
<li><a href="uganda.html">uganda</a></li>
</ul></dd>

<dt>Basic editing</dt>
<dd><ul>
<li><a href="starting.html">starting</a></li>
<li><a href="editing.html">editing</a></li>
<li><a href="motion.html">motion</a></li>
<li><a href="scroll.html">scroll</a></li>
<li><a href="insert.html">insert</a></li>
<li><a href="change.html">change</a></li>
<li><a href="indent.html">indent</a></li>
<li><a href="undo.html">undo</a></li>
<li><a href="repeat.html">repeat</a></li>
<li><a href="visual.html">visual</a></li>
<li><a href="various.html">various</a></li>
<li><a href="recover.html">recover</a></li>
</ul></dd>

<dt>Advanced editing</dt>
<dd><ul>
<li><a href="cmdline.html">cmdline</a></li>
<li><a href="options.html">options</a></li>
<li><a href="pattern.html">pattern</a></li>
<li><a href="map.html">map</a></li>
<li><a href="tagsrch.html">tagsrch</a></li>
<li><a href="quickfix.html">quickfix</a></li>
<li><a href="windows.html">windows</a></li>
<li><a href="tabpage.html">tabpage</a></li>
<li><a href="syntax.html">syntax</a></li>
<li><a href="spell.html">spell</a></li>
<li><a href="diff.html">diff</a></li>
<li><a href="autocmd.html">autocmd</a></li>
<li><a href="filetype.html">filetype</a></li>
<li><a href="eval.html">eval</a></li>
<li><a href="channel.html">channel</a></li>
<li><a href="fold.html">fold</a></li>
</ul></dd>

<dt>Special issues</dt>
<dd><ul>
<li><a href="print.html">print</a></li>
<li><a href="remote.html">remote</a></li>
<li><a href="term.html">term</a></li>
<li><a href="digraph.html">digraph</a></li>
<li><a href="mbyte.html">mbyte</a></li>
<li><a href="mlang.html">mlang</a></li>
<li><a href="arabic.html">arabic</a></li>
<li><a href="farsi.html">farsi</a></li>
<li><a href="hebrew.html">hebrew</a></li>
<li><a href="russian.html">russian</a></li>
<li><a href="ft_ada.html">ft_ada</a></li>
<li><a href="ft_sql.html">ft_sql</a></li>
<li><a href="hangulin.html">hangulin</a></li>
<li><a href="rileft.html">rileft</a></li>
</ul></dd>

<dt>GUI</dt>
<dd><ul>
<li><a href="gui.html">gui</a></li>
<li><a href="gui_w32.html">gui_w32</a></li>
<li><a href="gui_x11.html">gui_x11</a></li>
</ul></dd>

<dt>Interfaces</dt>
<dd><ul>
<li><a href="if_cscop.html">if_cscop</a></li>
<li><a href="if_lua.html">if_lua</a></li>
<li><a href="if_mzsch.html">if_mzsch</a></li>
<li><a href="if_perl.html">if_perl</a></li>
<li><a href="if_pyth.html">if_pyth</a></li>
<li><a href="if_tcl.html">if_tcl</a></li>
<li><a href="if_ole.html">if_ole</a></li>
<li><a href="if_ruby.html">if_ruby</a></li>
<li><a href="debugger.html">debugger</a></li>
<li><a href="workshop.html">workshop</a></li>
<li><a href="netbeans.html">netbeans</a></li>
<li><a href="sign.html">sign</a></li>
</ul></dd>

<dt>Versions</dt>
<dd><ul>
<li><a href="vi_diff.html">vi_diff</a></li>
<li><a href="version4.html">version4</a></li>
<li><a href="version5.html">version5</a></li>
<li><a href="version6.html">version6</a></li>
<li><a href="version7.html">version7</a></li>
<li><a href="version8.html">version8</a></li>
</ul></dd>

<dt>Remarks about specific systems</dt>
<dd><ul>
<li><a href="os_390.html">os_390</a></li>
<li><a href="os_amiga.html">os_amiga</a></li>
<li><a href="os_beos.html">os_beos</a></li>
<li><a href="os_dos.html">os_dos</a></li>
<li><a href="os_mac.html">os_mac</a></li>
<li><a href="os_mint.html">os_mint</a></li>
<li><a href="os_msdos.html">os_msdos</a></li>
<li><a href="os_os2.html">os_os2</a></li>
<li><a href="os_qnx.html">os_qnx</a></li>
<li><a href="os_risc.html">os_risc</a></li>
<li><a href="os_unix.html">os_unix</a></li>
<li><a href="os_vms.html">os_vms</a></li>
<li><a href="os_win32.html">os_win32</a></li>
</ul></dd>

<dt>Standard plugins</dt>
<dd><ul>
<li><a href="pi_getscript.html">pi_getscript</a></li>
<li><a href="pi_gzip.html">pi_gzip</a></li>
<li><a href="pi_logipat.html">pi_logipat</a></li>
<li><a href="pi_netrw.html">pi_netrw</a></li>
<li><a href="pi_paren.html">pi_paren</a></li>
<li><a href="pi_tar.html">pi_tar</a></li>
<li><a href="pi_vimball.html">pi_vimball</a></li>
<li><a href="pi_zip.html">pi_zip</a></li>
</ul></dd>

<dt>Filetype plugins</dt>
<dd><ul>
<li><a href="pi_spec.html">pi_spec</a></li>
</ul></dd>

<dt>Others</dt>
<dd><ul>
<li><a href="vim_faq.html">vim_faq</a></li>
</ul></dd>

</dl>
</nav>

<article class="Vimdoc VimdocJa">
<div id='vimCodeElement'>
<a class="Constant" href="usr_23.html" name="usr_23.txt">usr_23.txt</a>&nbsp;&nbsp;&nbsp;&nbsp;For&nbsp;<span class="Identifier">Vim version 8.0.</span>&nbsp;&nbsp;Last change: 2006 Apr 24<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; VIM USER MANUAL - by Bram Moolenaar<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Editing other files<br>
<br>
<br>
This chapter is about editing files that are not ordinary files.&nbsp;&nbsp;With Vim you<br>
can edit files that are compressed or encrypted.&nbsp;&nbsp;Some files need to be<br>
accessed over the internet.&nbsp;&nbsp;With some restrictions, binary files can be<br>
edited as well.<br>
<br>
<a class="Identifier" href="usr_23.html#23.1">23.1</a>&nbsp;&nbsp;DOS, Mac and Unix files<br>
<a class="Identifier" href="usr_23.html#23.2">23.2</a>&nbsp;&nbsp;Files on the internet<br>
<a class="Identifier" href="usr_23.html#23.3">23.3</a>&nbsp;&nbsp;Encryption<br>
<a class="Identifier" href="usr_23.html#23.4">23.4</a>&nbsp;&nbsp;Binary files<br>
<a class="Identifier" href="usr_23.html#23.5">23.5</a>&nbsp;&nbsp;Compressed files<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp; Next chapter:&nbsp;<a class="Identifier" href="usr_24.html">usr_24.txt</a>&nbsp;&nbsp;Inserting quickly<br>
&nbsp;Previous chapter:&nbsp;<a class="Identifier" href="usr_22.html">usr_22.txt</a>&nbsp;&nbsp;Finding the file to edit<br>
Table of contents:&nbsp;<a class="Identifier" href="usr_toc.html">usr_toc.txt</a><br>
<br>
<span class="PreProc">==============================================================================</span><br>
<a class="Constant" href="usr_23.html#23.1" name="23.1">23.1</a>&nbsp;&nbsp;DOS, Mac and Unix files<br>
<br>
Back in the early days, the old Teletype machines used two characters to<br>
start a new line.&nbsp;&nbsp;One to move the carriage back to the first position<br>
(carriage return,&nbsp;<span class="Special">&lt;CR&gt;</span>), another to move the paper up (line feed,&nbsp;<span class="Special">&lt;LF&gt;</span>).<br>
&nbsp;&nbsp; When computers came out, storage was expensive.&nbsp;&nbsp;Some people decided that<br>
they did not need two characters for end-of-line.&nbsp;&nbsp;The UNIX people decided<br>
they could use &lt;Line Feed&gt; only for end-of-line.&nbsp;&nbsp;The Apple people<br>
standardized on&nbsp;<span class="Special">&lt;CR&gt;</span>.&nbsp;&nbsp;The MS-DOS (and Microsoft Windows) folks decided to<br>
keep the old&nbsp;<span class="Special">&lt;CR&gt;&lt;LF&gt;</span>.<br>
&nbsp;&nbsp; This means that if you try to move a file from one system to another, you<br>
have line-break problems.&nbsp;&nbsp;The Vim editor automatically recognizes the<br>
different file formats and handles things properly behind your back.<br>
&nbsp;&nbsp; The option&nbsp;<a class="Type" href="options.html#'fileformats'">'fileformats'</a>&nbsp;contains the various formats that will be tried<br>
when a new file is edited.&nbsp;&nbsp;The following command, for example, tells Vim to<br>
try UNIX format first and MS-DOS format second:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:set fileformats=unix,dos</div>
<br>
You will notice the format in the message you get when editing a file.&nbsp;&nbsp;You<br>
don't see anything if you edit a native file format.&nbsp;&nbsp;Thus editing a Unix file<br>
on Unix won't result in a remark.&nbsp;&nbsp;But when you edit a dos file, Vim will<br>
notify you of this:<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">&quot;/tmp/test&quot; [dos] 3L, 71C</span><br>
<br>
For a Mac file you would see &quot;[mac]&quot;.<br>
&nbsp;&nbsp; The detected file format is stored in the&nbsp;<a class="Type" href="options.html#'fileformat'">'fileformat'</a>&nbsp;option.&nbsp;&nbsp;To see<br>
which format you have, execute the following command:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:set fileformat?</div>
<br>
The three names that Vim uses are:<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;unix&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="Special">&lt;LF&gt;</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dos&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="Special">&lt;CR&gt;&lt;LF&gt;</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;mac&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="Special">&lt;CR&gt;</span><br>
<br>
<br>
USING THE MAC FORMAT<br>
<br>
On Unix,&nbsp;<span class="Special">&lt;LF&gt;</span>&nbsp;is used to break a line.&nbsp;&nbsp;It's not unusual to have a&nbsp;<span class="Special">&lt;CR&gt;</span><br>
character halfway a line.&nbsp;&nbsp;Incidentally, this happens quite often in Vi (and<br>
Vim) scripts.<br>
&nbsp;&nbsp; On the Macintosh, where&nbsp;<span class="Special">&lt;CR&gt;</span>&nbsp;is the line break character, it's possible to<br>
have a&nbsp;<span class="Special">&lt;LF&gt;</span>&nbsp;character halfway a line.<br>
&nbsp;&nbsp; The result is that it's not possible to be 100% sure whether a file<br>
containing both&nbsp;<span class="Special">&lt;CR&gt;</span>&nbsp;and&nbsp;<span class="Special">&lt;LF&gt;</span>&nbsp;characters is a Mac or a Unix file.&nbsp;&nbsp;Therefore,<br>
Vim assumes that on Unix you probably won't edit a Mac file, and doesn't check<br>
for this type of file.&nbsp;&nbsp;To check for this format anyway, add &quot;mac&quot; to<br>
<a class="Type" href="options.html#'fileformats'">'fileformats'</a>:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:set fileformats+=mac</div>
<br>
Then Vim will take a guess at the file format.&nbsp;&nbsp;Watch out for situations where<br>
Vim guesses wrong.<br>
<br>
<br>
OVERRULING THE FORMAT<br>
<br>
If you use the good old Vi and try to edit an MS-DOS format file, you will<br>
find that each line ends with a ^M character.&nbsp;&nbsp;(^M is&nbsp;<span class="Special">&lt;CR&gt;</span>).&nbsp;&nbsp;The automatic<br>
detection avoids this.&nbsp;&nbsp;Suppose you do want to edit the file that way?&nbsp;&nbsp;Then<br>
you need to overrule the format:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:edit ++ff=unix file.txt</div>
<br>
The &quot;++&quot; string is an item that tells Vim that an option name follows, which<br>
overrules the default for this single command.&nbsp;&nbsp;&quot;++ff&quot; is used for<br>
<a class="Type" href="options.html#'fileformat'">'fileformat'</a>.&nbsp;&nbsp;You could also use &quot;++ff=mac&quot; or &quot;++ff=dos&quot;.<br>
&nbsp;&nbsp; This doesn't work for any option, only &quot;++ff&quot; and &quot;++enc&quot; are currently<br>
implemented.&nbsp;&nbsp;The full names &quot;++fileformat&quot; and &quot;++encoding&quot; also work.<br>
<br>
<br>
CONVERSION<br>
<br>
You can use the&nbsp;<a class="Type" href="options.html#'fileformat'">'fileformat'</a>&nbsp;option to convert from one file format to<br>
another.&nbsp;&nbsp;Suppose, for example, that you have an MS-DOS file named README.TXT<br>
that you want to convert to UNIX format.&nbsp;&nbsp;Start by editing the MS-DOS format<br>
file:<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;vim README.TXT</div>
<br>
Vim will recognize this as a dos format file.&nbsp;&nbsp;Now change the file format to<br>
UNIX:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:set fileformat=unix<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:write</div>
<br>
The file is written in Unix format.<br>
<br>
<span class="PreProc">==============================================================================</span><br>
<a class="Constant" href="usr_23.html#23.2" name="23.2">23.2</a>&nbsp;&nbsp;Files on the internet<br>
<br>
Someone sends you an e-mail message, which refers to a file by its URL.&nbsp;&nbsp;For<br>
example:<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">You can find the information here:</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="Constant">ftp://ftp.vim.org/pub/vim/README</span>&nbsp;<br>
<br>
You could start a program to download the file, save it on your local disk and<br>
then start Vim to edit it.<br>
&nbsp;&nbsp; There is a much simpler way.&nbsp;&nbsp;Move the cursor to any character of the URL.<br>
Then use this command:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;gf</div>
<br>
With a bit of luck, Vim will figure out which program to use for downloading<br>
the file, download it and edit the copy.&nbsp;&nbsp;To open the file in a new window use<br>
<span class="Special">CTRL-W</span>&nbsp;f.<br>
&nbsp;&nbsp; If something goes wrong you will get an error message.&nbsp;&nbsp;It's possible that<br>
the URL is wrong, you don't have permission to read it, the network connection<br>
is down, etc.&nbsp;&nbsp;Unfortunately, it's hard to tell the cause of the error.&nbsp;&nbsp;You<br>
might want to try the manual way of downloading the file.<br>
<br>
Accessing files over the internet works with the netrw plugin.&nbsp;&nbsp;Currently URLs<br>
with these formats are recognized:<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ftp://&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;uses ftp<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;rcp://&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;uses rcp<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scp://&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;uses scp<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="http://&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp">http://&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp</a>; uses wget (reading only)<br>
<br>
Vim doesn't do the communication itself, it relies on the mentioned programs<br>
to be available on your computer.&nbsp;&nbsp;On most Unix systems &quot;ftp&quot; and &quot;rcp&quot; will<br>
be present.&nbsp;&nbsp;&quot;scp&quot; and &quot;wget&quot; might need to be installed.<br>
<br>
Vim detects these URLs for each command that starts editing a new file, also<br>
with &quot;:edit&quot; and &quot;:split&quot;, for example.&nbsp;&nbsp;Write commands also work, except for<br>
<a href="http://.">http://.</a><br>
<br>
For more information, also about passwords, see&nbsp;<a class="Identifier" href="pi_netrw.html#netrw">netrw</a>.<br>
<br>
<span class="PreProc">==============================================================================</span><br>
<a class="Constant" href="usr_23.html#23.3" name="23.3">23.3</a>&nbsp;&nbsp;Encryption<br>
<br>
Some information you prefer to keep to yourself.&nbsp;&nbsp;For example, when writing<br>
a test on a computer that students also use.&nbsp;&nbsp;You don't want clever students<br>
to figure out a way to read the questions before the exam starts.&nbsp;&nbsp;Vim can<br>
encrypt the file for you, which gives you some protection.<br>
&nbsp;&nbsp; To start editing a new file with encryption, use the &quot;-x&quot; argument to start<br>
Vim.&nbsp;&nbsp;Example:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;vim -x exam.txt</div>
<br>
Vim prompts you for a key used for encrypting and decrypting the file:<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">Enter encryption key:</span><br>
<br>
Carefully type the secret key now.&nbsp;&nbsp;You cannot see the characters you type,<br>
they will be replaced by stars.&nbsp;&nbsp;To avoid the situation that a typing mistake<br>
will cause trouble, Vim asks you to enter the key again:<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">Enter same key again:</span><br>
<br>
You can now edit this file normally and put in all your secrets.&nbsp;&nbsp;When you<br>
finish editing the file and tell Vim to exit, the file is encrypted and<br>
written.<br>
&nbsp;&nbsp; When you edit the file with Vim, it will ask you to enter the same key<br>
again.&nbsp;&nbsp;You don't need to use the &quot;-x&quot; argument.&nbsp;&nbsp;You can also use the normal<br>
&quot;:edit&quot; command.&nbsp;&nbsp;Vim adds a magic string to the file by which it recognizes<br>
that the file was encrypted.<br>
&nbsp;&nbsp; If you try to view this file using another program, all you get is garbage.<br>
Also, if you edit the file with Vim and enter the wrong key, you get garbage.<br>
Vim does not have a mechanism to check if the key is the right one (this makes<br>
it much harder to break the key).<br>
<br>
<br>
SWITCHING ENCRYPTION ON AND OFF<br>
<br>
To disable the encryption of a file, set the&nbsp;<a class="Type" href="options.html#'key'">'key'</a>&nbsp;option to an empty string:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:set key=</div>
<br>
The next time you write the file this will be done without encryption.<br>
&nbsp;&nbsp; Setting the&nbsp;<a class="Type" href="options.html#'key'">'key'</a>&nbsp;option to enable encryption is not a good idea, because<br>
the password appears in the clear.&nbsp;&nbsp;Anyone shoulder-surfing can read your<br>
password.<br>
&nbsp;&nbsp; To avoid this problem, the &quot;:X&quot; command was created.&nbsp;&nbsp;It asks you for an<br>
encryption key, just like the &quot;-x&quot; argument did:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:X<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Enter encryption key: ******<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Enter same key again: ******</div>
<br>
<br>
LIMITS ON ENCRYPTION<br>
<br>
The encryption algorithm used by Vim is weak.&nbsp;&nbsp;It is good enough to keep out<br>
the casual prowler, but not good enough to keep out a cryptology expert with<br>
lots of time on his hands.&nbsp;&nbsp;Also you should be aware that the swap file is not<br>
encrypted; so while you are editing, people with superuser privileges can read<br>
the unencrypted text from this file.<br>
&nbsp;&nbsp; One way to avoid letting people read your swap file is to avoid using one.<br>
If the -n argument is supplied on the command line, no swap file is used<br>
(instead, Vim puts everything in memory).&nbsp;&nbsp;For example, to edit the encrypted<br>
file &quot;file.txt&quot; without a swap file use the following command:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;vim -x -n file.txt</div>
<br>
When already editing a file, the swapfile can be disabled with:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:setlocal noswapfile</div>
<br>
Since there is no swapfile, recovery will be impossible.&nbsp;&nbsp;Save the file a bit<br>
more often to avoid the risk of losing your changes.<br>
<br>
While the file is in memory, it is in plain text.&nbsp;&nbsp;Anyone with privilege can<br>
look in the editor's memory and discover the contents of the file.<br>
&nbsp;&nbsp; If you use a viminfo file, be aware that the contents of text registers are<br>
written out in the clear as well.<br>
&nbsp;&nbsp; If you really want to secure the contents of a file, edit it only on a<br>
portable computer not connected to a network, use good encryption tools, and<br>
keep the computer locked up in a big safe when not in use.<br>
<br>
<span class="PreProc">==============================================================================</span><br>
<a class="Constant" href="usr_23.html#23.4" name="23.4">23.4</a>&nbsp;&nbsp;Binary files<br>
<br>
You can edit binary files with Vim.&nbsp;&nbsp;Vim wasn't really made for this, thus<br>
there are a few restrictions.&nbsp;&nbsp;But you can read a file, change a character and<br>
write it back, with the result that only that one character was changed and<br>
the file is identical otherwise.<br>
&nbsp;&nbsp; To make sure that Vim does not use its clever tricks in the wrong way, add<br>
the &quot;-b&quot; argument when starting Vim&#0058;<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;vim -b datafile</div>
<br>
This sets the&nbsp;<a class="Type" href="options.html#'binary'">'binary'</a>&nbsp;option.&nbsp;&nbsp;The effect of this is that unexpected side<br>
effects are turned off.&nbsp;&nbsp;For example,&nbsp;<a class="Type" href="options.html#'textwidth'">'textwidth'</a>&nbsp;is set to zero, to avoid<br>
automatic formatting of lines.&nbsp;&nbsp;And files are always read in Unix file format.<br>
<br>
Binary mode can be used to change a message in a program.&nbsp;&nbsp;Be careful not to<br>
insert or delete any characters, it would stop the program from working.&nbsp;&nbsp;Use<br>
&quot;R&quot; to enter replace mode.<br>
<br>
Many characters in the file will be unprintable.&nbsp;&nbsp;To see them in Hex format:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:set display=uhex</div>
<br>
Otherwise, the &quot;ga&quot; command can be used to see the value of the character<br>
under the cursor.&nbsp;&nbsp;The output, when the cursor is on an&nbsp;<span class="Special">&lt;Esc&gt;</span>, looks like<br>
this:<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">&lt;^[&gt;&nbsp;&nbsp;27,&nbsp;&nbsp;Hex 1b,&nbsp;&nbsp;Octal 033</span><br>
<br>
There might not be many line breaks in the file.&nbsp;&nbsp;To get some overview switch<br>
the&nbsp;<a class="Type" href="options.html#'wrap'">'wrap'</a>&nbsp;option off:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:set nowrap</div>
<br>
<br>
BYTE POSITION<br>
<br>
To see on which byte you are in the file use this command:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;g CTRL-G</div>
<br>
The output is verbose:<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">Col 9-16 of 9-16; Line 277 of 330; Word 1806 of 2058; Byte 10580 of 12206</span><br>
<br>
The last two numbers are the byte position in the file and the total number of<br>
bytes.&nbsp;&nbsp;This takes into account how&nbsp;<a class="Type" href="options.html#'fileformat'">'fileformat'</a>&nbsp;changes the number of bytes<br>
that a line break uses.<br>
&nbsp;&nbsp;&nbsp;&nbsp;To move to a specific byte in the file, use the &quot;go&quot; command.&nbsp;&nbsp;For<br>
example, to move to byte 2345:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;2345go</div>
<br>
<br>
USING XXD<br>
<br>
A real binary editor shows the text in two ways: as it is and in hex format.<br>
You can do this in Vim by first converting the file with the &quot;xxd&quot; program.<br>
This comes with Vim.<br>
&nbsp;&nbsp; First edit the file in binary mode:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;vim -b datafile</div>
<br>
Now convert the file to a hex dump with xxd:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:%!xxd</div>
<br>
The text will look like this:<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">0000000: 1f8b 0808 39d7 173b 0203 7474 002b 4e49&nbsp;&nbsp;....9..;..tt.+NI</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">0000010: 4b2c 8660 eb9c ecac c462 eb94 345e 2e30&nbsp;&nbsp;K,.`.....b..4^.0</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="PreProc">0000020: 373b 2731 0b22 0ca6 c1a2 d669 1035 39d9&nbsp;&nbsp;7;'1.&quot;.....i.59.</span><br>
<br>
You can now view and edit the text as you like.&nbsp;&nbsp;Vim treats the information as<br>
ordinary text.&nbsp;&nbsp;Changing the hex does not cause the printable character to be<br>
changed, or the other way around.<br>
&nbsp;&nbsp; Finally convert it back with:<br>
<br>
<div class="helpExample">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:%!xxd -r</div>
<br>
Only changes in the hex part are used.&nbsp;&nbsp;Changes in the printable text part on<br>
the right are ignored.<br>
<br>
See the manual page of xxd for more information.<br>
<br>
<span class="PreProc">==============================================================================</span><br>
<a class="Constant" href="usr_23.html#23.5" name="23.5">23.5</a>&nbsp;&nbsp;Compressed files<br>
<br>
This is easy: You can edit a compressed file just like any other file.&nbsp;&nbsp;The<br>
&quot;gzip&quot; plugin takes care of decompressing the file when you edit it.&nbsp;&nbsp;And<br>
compressing it again when you write it.<br>
&nbsp;&nbsp; These compression methods are currently supported:<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.Z&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;compress<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.gz&nbsp;&nbsp;&nbsp;&nbsp; gzip<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.bz2&nbsp;&nbsp;&nbsp;&nbsp;bzip2<br>
<br>
Vim uses the mentioned programs to do the actual compression and<br>
decompression.&nbsp;&nbsp;You might need to install the programs first.<br>
<br>
<span class="PreProc">==============================================================================</span><br>
<br>
Next chapter:&nbsp;<a class="Identifier" href="usr_24.html">usr_24.txt</a>&nbsp;&nbsp;Inserting quickly<br>
<br>
Copyright: see&nbsp;<a class="Identifier" href="usr_01.html#manual-copyright">manual-copyright</a>&nbsp;&nbsp;vim:tw=78:ts=8:ft=help:norl:<br>
</div>

</article>

<footer>
<a href="#top">Return to the top</a> - <a href="index.html">Return to main</a>
<span class="EnglishJapaneseLink">
  <span class="CurrentLanguage">English</span>
</span>
<br />
<div style="text-align:right;">
Hosted by <a href="https://github.com/vim-jp/vimdoc-en">vimdoc-en project</a><br />
If you met any problem, please report it to <a href="https://github.com/vim-jp/vimdoc-en/issues">issue</a>.<br />
</div>
</footer>

<!--<script src="js/check-referrer.js" type="text/javascript"></script>-->

</body>
</html>
<!-- vim:set ts=8 sts=2 sw=2 tw=0 et: -->
